package jwanalytics.ejb.webhouse;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

/** 
 * This stores the whole information about a click stream.
 * This is a fact table as described on page 278 of [3].  
 * Explained on page 292, 293 of [3]. 
 * [3] Wiley - The Data Warehouse Toolkit - 2nd Edition.
 * @author aacesta
 */
@Entity
@Table(name="clickstream_page_event_fact")
public class ClickStreamPageEventFact {
	
	public Long sessionKey;
	
	public Integer startDateKey;
	
	public Integer startTimeOfDayKey;
	
	public Long refererKey;
	
	public Long startPageKey;
	
	public Long endPageKey;
	
	public Long customerKey;
	
	public Long returningBrowserKey;
	
	public Long clientSystemKey;
	
	public String ipAddress;
	
	public Integer sessionSeconds;
	
	public Integer pagesVisited = 0;
	
	public Integer averagePageTime = 0;
	
	public Boolean isReturningBrowser;
	
	/** This is not persisted, but used to calculate the averagePageTime. */
	public Integer totalPageTime = 0;
	
	@Id
	@Column(name="session_key")		
	public Long getSessionKey() {
		return sessionKey;
	}
	
	public void setSessionKey(Long sessionKey) {
		this.sessionKey = sessionKey;
	}
	
	@Column(name="start_date_key")			
	public Integer getStartDateKey() {
		return startDateKey;
	}
	
	public void setStartDateKey(Integer startDateKey) {
		this.startDateKey = startDateKey;
	}
	
	@Column(name="start_time_of_day_key")				
	public Integer getStartTimeOfDayKey() {
		return startTimeOfDayKey;
	}
	
	
	public void setStartTimeOfDayKey(Integer startTimeOfDayKey) {
		this.startTimeOfDayKey = startTimeOfDayKey;
	}
	
	@Column(name="referer_key")					
	public Long getRefererKey() {
		return refererKey;
	}
	
	public void setRefererKey(Long refererKey) {
		this.refererKey = refererKey;
	}
	
	@Column(name="start_page_key")						
	public Long getStartPageKey() {
		return startPageKey;
	}
	
	public void setStartPageKey(Long startPageKey) {
		this.startPageKey = startPageKey;
	}
	
	@Column(name="end_page_key")								
	public Long getEndPageKey() {
		return endPageKey;
	}
	
	public void setEndPageKey(Long endPageKey) {
		this.endPageKey = endPageKey;
	}
	
	@Column(name="customer_key")										
	public Long getCustomerKey() {
		return customerKey;
	}
	
	public void setCustomerKey(Long customerKey) {
		this.customerKey = customerKey;
	}
	
	@Column(name="returning_browser_key")											
	public Long getReturningBrowserKey() {
		return returningBrowserKey;
	}
	
	public void setReturningBrowserKey(Long returningBrowserKey) {
		this.returningBrowserKey = returningBrowserKey;
	}
	
	@Column(name="client_system_key")												
	public Long getClientSystemKey() {
		return clientSystemKey;
	}
	
	public void setClientSystemKey(Long clientSystemKey) {
		this.clientSystemKey = clientSystemKey;
	}
	
	@Column(name="ip_address")													
	public String getIpAddress() {
		return this.ipAddress;
	}
	
	public void setIpAddress(String ipAddress) {
		this.ipAddress = ipAddress;
	}
	
	@Column(name="session_seconds")														
	public Integer getSessionSeconds() {
		return sessionSeconds;
	}
		
	public void setSessionSeconds(Integer sessionSeconds) {
		this.sessionSeconds = sessionSeconds;
	}
	
	@Column(name="pages_visited")															
	public Integer getPagesVisited() {
		return pagesVisited;
	}
	
	public void setPagesVisited(Integer pagesVisited) {
		this.pagesVisited = pagesVisited;
	}
	
	@Column(name="average_page_time")																
	public Integer getAveragePageTime() {
		return averagePageTime;
	}
	
	public void setAveragePageTime(Integer averagePageTime) {
		this.averagePageTime = averagePageTime;
	}
	
	@Column(name="is_returning_browser")	
	public char getIsReturningBrowser() {
		//always converts to lowercase
		if (isReturningBrowser == null) return 'n';
		if (isReturningBrowser) return 'y';
		return 'y';
	}
	
	public void setIsReturningBrowser(char value) {
		if (value == 'y' || value == 'Y') {
			isReturningBrowser = true;
		} else {
			isReturningBrowser = false;
		}
	}
	
	@Transient
	public int getTotalPageTime() {
		return totalPageTime;
	}
	
	public void setTotalPageTime(int totalPageTime) {
		this.totalPageTime = totalPageTime;
	}
	
}
